/**
 * Obtem um numero aleatorio.
 * 
 * @param lbound
 * @param ubound
 * @returns
 */
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

/**
 * Gera um caracter aleatorio utilizando a função getRandomNum.
 * 
 * @param number
 * @param lower
 * @param upper
 * @param other
 * @param extra
 * @returns
 */
function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	var charSet = extra;
	if (number == true)
		charSet += numberChars;
	if (lower == true)
		charSet += lowerChars;
	if (upper == true)
		charSet += upperChars;
	if (other == true)
		charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}

/**
 * Gera um password/senha utilizando a funcao getRandomChar.
 * 
 * @param length
 * @param extraChars
 * @param firstNumber
 * @param firstLower
 * @param firstUpper
 * @param firstOther
 * @param latterNumber
 * @param latterLower
 * @param latterUpper
 * @param latterOther
 * @returns {String}
 */
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
		latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
	if (length > 0)
		rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
	for (var idx = 1; idx < length; ++idx) {
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
	}
	return rc;
}